package com.example.download

import android.content.Intent
import android.os.Bundle
import android.widget.ImageView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.download.adapter.setting_itemAdapter
import com.example.download.bean.setting_item
import com.example.download.databinding.ActivitySettingBinding

class Setting : AppCompatActivity() {
    private lateinit var activitySettingBinding: ActivitySettingBinding
    private lateinit var settingView: RecyclerView
    private lateinit var settingItemAdapter: setting_itemAdapter
    private lateinit var settingItemList: List<setting_item>
    private lateinit var ivAsBack: ImageView


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        activitySettingBinding = ActivitySettingBinding.inflate(layoutInflater)
        setContentView(activitySettingBinding.root)
        ViewCompat.setOnApplyWindowInsetsListener(activitySettingBinding.main) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        settingItemList = listOf(
            setting_item(set_id = 1, iv_si_illustration = R.mipmap.question1, tv_si_title = "How to use", iv_si_next = R.mipmap.normalback),
            setting_item(set_id = 2,iv_si_illustration = R.mipmap.folder_export_file, tv_si_title = "Download Path", tv_si_content = "/storage/emulated/0/Download/VideoFolder/Tiktok/How to unlock your iPhone with your App"),
            setting_item(set_id = 3,iv_si_illustration = R.mipmap.earth, tv_si_title = "Language",  tv_si_language = "English", iv_si_next = R.mipmap.normalback),
            setting_item(set_id = 4, iv_si_illustration = R.mipmap.notebook, tv_si_title = "Privacy Policy",   iv_si_next = R.mipmap.normalback),
            setting_item(set_id = 5, iv_si_illustration = R.mipmap.ebook, tv_si_title = "Terms of use", iv_si_next = R.mipmap.normalback)
        )
        settingView = activitySettingBinding.asRecyclerView
        settingView.layoutManager = LinearLayoutManager(this)


        settingItemAdapter = setting_itemAdapter(settingItemList, object : setting_itemAdapter.OnItemClickListener {
            override fun onItemClick(id: Int) {
                 val intent = when (id) {
                    1 -> Intent(this@Setting, Help::class.java)
                    4 -> Intent(this@Setting, MainActivity::class.java)
                    5 -> Intent(this@Setting, MainActivity::class.java)
                    else -> null
                }
                intent?.let { startActivity(it) }
            }
        })
        settingView.adapter = settingItemAdapter
        ivAsBack = activitySettingBinding.ivAsBack
        ivAsBack.setOnClickListener {
            finish()
        }

    }
}